﻿using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using UmbSearch2.Search;

namespace UmbSearch2.EventHandlers
{
	public class DocumentIndexer : ApplicationBase
	{
		public DocumentIndexer()
		{
			Document.AfterPublish += Document_AfterPublish;
			Document.AfterUnPublish += Document_AfterUnPublish;
		}

		void Document_AfterUnPublish(Document sender, umbraco.cms.businesslogic.UnPublishEventArgs e)
		{
			// remove node from the index
			Indexer.RemoveNode(sender.Id);
		}

		void Document_AfterPublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
		{
			Indexer.Index(sender);
		}
	}
}